import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'default-passive-events'
import './assets/styles/reset.scss'
// 引入字体图标库
import 'element-ui/lib/theme-chalk/icon.css'
// import 'element-ui/lib/theme-chalk/index.css'
// 引入默认主题样式
import './assets/theme/default/styls.scss'
import md5 from './Plugins/md5'
import elTableTransfer from 'el-table-transfer'
Vue.use(elTableTransfer)
Vue.use(md5)

Vue.config.productionTip = false

Vue.use(ElementUI)

const on = Vue.prototype.$on
// 防抖处理
Vue.prototype.$on = function (event, func) {
  let timer
  let newFunc = func
  if (event === 'click') {
    newFunc = function () {
      clearTimeout(timer)
      timer = setTimeout(function () {
        func.apply(this, arguments)
      }, 500)
    }
  }
  on.call(this, event, newFunc)
}

//
// const on = Vue.prototype.$on
//
// // 节流
// Vue.prototype.$on = function (event, func) {
//   let previous = 0
//   let newFunc = func
//   if (event === 'click') {
//     newFunc = function () {
//       const now = new Date().getTime()
//       if (previous + 1000 <= now) {
//         func.apply(this, arguments)
//         previous = now
//       }
//     }
//   }
//   on.call(this, event, newFunc)
// }
// 页面刷新时，重新赋值
if (window.sessionStorage.getItem('userData')) {
  let data = JSON.parse(window.sessionStorage.getItem('userData'))
  store.dispatch('ChangeTheme', data.theme)
}

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
